package com.wtwd.wtwddevice.listener.appMsg;

import com.wtwd.device.annotation.MsgType;
import com.wtwd.device.constant.AnswerStateEnum;
import com.wtwd.device.constant.CmdStateEnum;
import com.wtwd.device.constant.Constant;
import com.wtwd.device.constant.MsgTypeEnum;
import com.wtwd.device.model.SetAlarm;
import com.wtwd.device.mqtentity.MessageBase;
import com.wtwd.device.protocol.AppProtocol;
import com.wtwd.device.protocol.WTProtocol;
import com.wtwd.device.util.StringUtils;
import com.wtwd.wtwddevice.listener.deviceServerMsg.handler.IMsgHandler;
import com.wtwd.wtwddevice.model.entity.DeviceAlarmInfo;
import com.wtwd.wtwddevice.mq.PushAppMsgService;
import com.wtwd.wtwddevice.service.IDeviceSendService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@MsgType(MsgTypeEnum.APP_LOCATION_INFO_GET)
@Component
public class AppLocationInfoGetHandler implements IMsgHandler{

    @Resource
    private IDeviceSendService deviceSendService;

    @Resource
    private PushAppMsgService msgService;

    @Override
    public void handleMsg(MessageBase messageBase) {
        AppProtocol appProtocol = messageBase.getAppProtocol();
        WTProtocol wtProtocol = WTProtocol.builder()
                .imei(appProtocol.getImei())
                .cmdName(MsgTypeEnum.LOCATION_INFO_GET.getCmdName())
                .bodyLength(0)
                .build();
        if (!deviceSendService.sendMsgDevice(wtProtocol)) {//如果为fase直接告知app端设置失败
            AppProtocol protocol = AppProtocol.builder()
                    .imei(wtProtocol.getImei())
                    .cmdName(MsgTypeEnum.APP_LOCATION_INFO_GET.getCmdName())
                    .state(AnswerStateEnum.ABNORMAL.getState())
                    .data(null)
                    .build();
            msgService.pushToDevice(messageBase.getForm(),
                    MessageBase.builder()
                            .appProtocol(protocol)
                            .build()
            );
        }
    }

}
